import 'package:flutter_learn_vi/src/bean/bean_problem.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/1/24.
///
/// 可关注公众号：我的大前端生涯   获取最新技术分享
/// 可关注网易云课堂：https://study.163.com/instructor/1021406098.htm
/// 可关注博客：https://blog.csdn.net/zl18603543572
///
/// 代码清单
///代码清单
class WrongModel {
  ///[isNul] 值为true 时 ，未作答的题也为N
  ///        值为 false 时，未消作答的题为 null
  String checkQuestionFunction(ProblemModel problemModel, {bool isNul = true}) {
    String rightAnswer = "Y";
    String myAnswer = "";
    List<String> myAnswerList = [];
    List<String> rightAnswerList = [];

    if (problemModel.themAnswerStr != null &&
        problemModel.themAnswerStr.trim().length > 0) {
      problemModel.themAnswerStr = problemModel.themAnswerStr.toUpperCase();
      for (var i = 0; i < problemModel.themAnswerStr.length; ++i) {
        myAnswerList.add(problemModel.themAnswerStr.substring(i, i + 1));
      }
    } else {
      return null;
    }

    if (problemModel.answer != null) {
      problemModel.answer = problemModel.answer.toUpperCase();
      for (var i = 0; i < problemModel.answer.length; ++i) {
        rightAnswerList.add(problemModel.answer.substring(i, i + 1));
      }
    }
    myAnswerList.sort();
    rightAnswerList.sort();

    String checkMyAnswer = myAnswerList.toString();
    String checkRightAnswer = rightAnswerList.toString();
    if (checkMyAnswer == checkRightAnswer) {
      rightAnswer = "Y";
      return "回答正确";
    } else {
      rightAnswer = "N";
      return "回答错误 正确答案是 $checkRightAnswer";
    }
  }
}
